package SM.UI;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import SM.UI.Controls.DropDown;
import SM.UI.Controls.Table;
import SM.BusinessLogic.DBAccess;
import SM.BusinessLogic.DBService;

/**
 * Servlet implementation class ReportIssue
 */

public class ContactUs extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public ContactUs() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// doGet is used to render HTML content
	
		/*Variable Declaration*/
		
		PrintWriter out = response.getWriter();
		SM.UI.Controls.Table tblContactUs = new Table("contact-us", 100, "t");
		
		request.getRequestDispatcher("contact-1.html").include(request, response);
		
		//display table 
		
		/*This should happen in isolation*/
		
		synchronized(this) { 
		
		/*Prolog*/
				Connection connection = DBAccess.MakeConnection();
				CallableStatement statement = DBAccess.GetStatementForProcedureCall(connection, "ContactsSelect()");
		
				ResultSet resultSet = DBService.ExecuteProcedure(connection, statement);
		
		/*Actual table data*/
		
				tblContactUs.SetDataSource(resultSet, 3);

				out.println(tblContactUs.getHTML(connection));
		
		/*Epilogue*/
				DBAccess.CloseConnection(connection);
				DBAccess.CloseStatement(statement);
		}
		
		//table display over
		
		String DisplayString = "<br class=\"clearfix\"/>" +
		
		"</div>"+
		"</div>"+

		"</body>"+
		"</html>";
		
		out.println(DisplayString);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// doPost is used to Accept request from page and Make Changes
		
		
	}

}
